<template>
  <div class="login_page">
    <div class="content">

      <div class="content_box">
        <h2>通用管理后台</h2>
        <div class="login--box">
          <a-form ref="loginForm" :rules="loginRules" :model="formData">
            <a-form-item name="username">
              <a-input v-model:value.trim="formData.username" placeholder="请输入登录账号">
              </a-input>
            </a-form-item>
            <a-form-item name="userpwd">
              <a-input-password v-model:value.trim="formData.userpwd" placeholder="请输入密码">
              </a-input-password>
            </a-form-item>
          </a-form>

          <a-button type="primary" style="width: 100%;" @click="goLogin1"> 登 录 </a-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { login } from "@/api/login";
// import axios from "axios";
// import md5 from "js-md5";


export default {
  data() {
    return {
      formData: {
        username: "",
        userpwd: "",
      },
      // 表单验证
      loginRules: {
        // username: [
        //   {
        //     type: "number",
        //     required: true,
        //     message: "请填写正确的手机号",
        //     transform(value) {
        //       var msg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
        //       if (!msg.test(value)) {
        //         return false;
        //       } else {
        //         return Number(value);
        //       }
        //     },
        //   },
        // ],
        // userpwd: [
        //   { required: true, message: "密码不能为空" },
        //   { type: "string", min: 8, message: "密码不少于8位" },
        //   { type: "string", max: 20, message: "密码不大于20位" },
        // ],
      },

    };
  },

  created() {
  },
  mounted() {

  },
  methods: {
    goLogin1() {
      this.$message.success("登录成功", 1);
      sessionStorage.setItem("token", '11');
      this.$router.push("/home");
    },
    //正式调用接口登录
    goLogin() {
      this.$refs.loginForm.validate().then((valid) => {
        if (valid) {
          if (this.formData.username == "" || this.formData.userpwd == "") {
            this.$message.error("请输入账号或密码", 1);
          } else {
            let params = {
              username: this.formData.username,
              // userpwd: md5(this.formData.userpwd),
              userpwd: this.formData.userpwd,
            };

            login(params)
              .then((res) => {
                console.log(res, 8888);

                if (res.code == 200) {
                  sessionStorage.setItem("token", res.accessToken || '');
                  // this.$store.commit("USER_INFO", res.resultData);
                  this.$message.success("登录成功", 1);
                  this.$router.push("/home");
                }
              })
              .catch(() => { });
          }
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.login_page {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  background: #f0f2f5;


  .content {
    // width: 20%;
    // height: 50%;
    width: 320px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;

    h2 {
      font-size: 24px;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-weight: 600;
      text-align: center;
      color: #3a3a3a;
      // line-height: 80px;
    }




  }
}
</style>
